package com.winner.chain_of_responsibility_pattern;

import java.util.Random;
/**
 * 经理处理者
 */
public class Manager extends Handler {
    public Manager(String name) {
        super(name);
    }

    @Override
    public boolean process(LeaveRequest leaveRequest) {
        // 随机数大于3则为批准，否则不批准
        boolean result = (new Random().nextInt(10)) > 3;
        if (result == false) {
            return false;
        } else if (leaveRequest.getDays() < 7) {
            // 批准且天数小于7
            return true;
        }
        // 批准且天数大于等于7，提交给下一个处理者处理
        return nextHandler.process(leaveRequest);
    }
}
